import requests
import time
from bs4 import BeautifulSoup
# urls='https://www.kugou.com/yy/rank/home/1-8888.html?from=rank'
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
def get_info(urls):
    data=requests.get(urls,headers=headers) #请求内容
    soup=BeautifulSoup(data.text,'html.parser')
    ranks = soup.select('#rankWrap > div.pc_temp_songlist > ul > li > span.pc_temp_num')
    song_infos=soup.select('#rankWrap > div.pc_temp_songlist > ul > li > a')
    times=soup.select('#rankWrap > div.pc_temp_songlist > ul > li > span.pc_temp_tips_r > span')
    for rank,song_info,time in zip(ranks,song_infos,times):
        result={
            '排名':rank.get_text().strip(),
            '歌手':song_info.get_text().split('-')[0],
            '歌曲':song_info.get_text().split('-')[-1],
            '歌曲时间':time.get_text().strip()
        }
        print(result)

if __name__=='__main__':
    urls=['https://www.kugou.com/yy/rank/home/{}-8888.html?from=rank'.format(str(i)) for i in range(1,23)] #链接
    for url in urls:
        get_info(url)   #调用函数
    time.sleep(2)   #时间静止